package com.example.math;

public class Calculator {
    /**
     * 加法运算
     */
    public static double add(double a, double b) {
        return a + b;
    }

    /**
     * 减法运算
     */
    public static double subtract(double a, double b) {
        return a - b;
    }

    /**
     * 乘法运算
     */
    public static double multiply(double a, double b) {
        return a * b;
    }

    /**
     * 除法运算
     */
    public static double divide(double a, double b) {
        if (b == 0) {
            throw new ArithmeticException("Division by zero");
        }
        return a / b;
    }

    /**
     * 复合运算 (a + b * c) / d
     */
    public static double complexOperation(double a, double b, double c, double d) {
        if (d == 0) {
            throw new ArithmeticException("Division by zero");
        }
        return (a + multiply(b, c)) / d;
    }

    /**
     * 平方根运算 sqrt(a * b)
     */
    public static double sqrtProduct(double a, double b) {
        double product = multiply(a, b);
        if (product < 0) {
            throw new ArithmeticException("Square root of negative number");
        }
        return Math.sqrt(product);
    }
}